import data from "../../../../core/cache_data";
import CheckBox from "../../../../prefabs/check_box";
import Ball from "./ball";
import PageGame, { PingPongGameConfig } from "./page_game";
import PlayerArea from "./player_area";

const { ccclass, property } = cc._decorator;

@ccclass
export default class PageGameDebug extends cc.Component {
    @property(cc.EditBox)
    ebSize: cc.EditBox = null;
    @property(cc.EditBox)
    ebDoorSize: cc.EditBox = null;
    pageGame: PageGame = null;

    @property(cc.EditBox)
    ebBallSpeed: cc.EditBox = null;
    @property(CheckBox)
    cbBallSpeedLimitation: CheckBox = null;
    protected onLoad(): void {
        this.pageGame = this.node.parent.getComponent(PageGame);
        this.cbBallSpeedLimitation.on("clicked", this.onBallSpeedLimitationChanged, this);
    }
    onClickChangeSize() {
        let size = Number(this.ebSize.string);
        if (!size) {
            return;
        }
        let config = data.cache.get<PingPongGameConfig>("ping-pong-game-config");
        config.handleSize = size;
        this.pageGame.updateConfig();
    }

    onClickChangeDoorSize() {
        let size = Number(this.ebDoorSize.string);
        if (!size) {
            return;
        }
        let config = data.cache.get<PingPongGameConfig>("ping-pong-game-config");
        config.doorSize = size;
        this.pageGame.updateConfig();
    }
    onBallSpeedLimitationChanged() {
        let ball = this.pageGame.table.getComponent(Ball);
        if (!ball) {
            return;
        }
        let config = data.cache.get<PingPongGameConfig>("ping-pong-game-config");
        config.speedLimitation = this.cbBallSpeedLimitation.checked;
        config.limitSpeed = Number(this.ebBallSpeed.string);
        this.pageGame.updateConfig();
    }
};